from core.basehandler import BaseHandler
from core.room import Room
from core.support import set_cutscene, get_game
from core.action import Action
from core.game import Game




class CouncilRoom(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)    
        # do basic initialization for every room
        #self.treasure_locked = True
        #self.lock_rusty = True
        
        # build list of actions
        self.locked = True
        self.solving = True
        self.add_action(GoFreeman)
        self.add_action(GoGradLounge)
        self.add_action(GoBallroom)
        self.add_action(goStupid)
        self.add_action(goLocked)
        #self.add_item(Vodka())
        #self.add_item(OrangeJuice())
        self.add_action(AnswerTwo)
        self.add_action(AnswerFive)
        self.add_action(AnswerSix)
    
    def get_description(self):
        game = get_game()
        player = game.get_player()
        if self.locked:
            if ('neil' in player.inventory):
                desc = "Have a council member unlock the door to the Council Room."
            else:
                desc = "You need to find a council member to let you into the Council Room."
        else:
            desc = "Solve the following puzzle to get a clue about where to go next: What is 2 + 3?"
        
        return desc
    
    def get_image(self):
        if self.locked==True:
            return 'councilclosed.jpg'
        else:
            return 'councilroom.jpg'
    

class CouncilRoomHandler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return CouncilRoom

# define actions for this room

class GoBallroom(Action):
    def __init__(self):
        Action.__init__(self, "Ballroom")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Go to the 9th floor ballroom"
    
    # set cutscene for when arrive in entrance_hall
    def do_action(self,game,room,request):
        set_cutscene("You hear music playing inside the ballroom.")
        return
    
    # return id of room to enter when action is complete
    def get_destination(self):
    #AMT-if have mary sforza, return ballroom, if not, then return lockedroom
        game = get_game()
        game.get_room('councilroom', CouncilRoom).locked = True
        game.get_room('councilroom', CouncilRoom).inventory.clear()
        #while (len(game.get_room('councilroom', CouncilRoom).inventory) > 0):
            #game.get_room('councilroom', CouncilRoom).inventory.pop()
        return 'ballroom'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
    #def is_enabled(self):
       # game = get_game()
       # if game.history[-1].solving:
        #    return False
        #else:
        #    return True

class GoFreeman(Action):
    def __init__(self):
        Action.__init__(self, "Dean Freeman's office")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Go to Dean Freeman's office"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        game = get_game()
        game.get_room('councilroom', CouncilRoom).locked = True
        game.get_room('councilroom', CouncilRoom).inventory.clear()
       # while (len(game.get_room('councilroom', CouncilRoom).inventory) > 0):
          #  game.get_room('councilroom', CouncilRoom).inventory.pop()
        return 'deanoffice'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
    #def is_enabled(self):
       # game = get_game()
       # if game.history[-1].solving:
        #    return False
       # else:
        #    return True

class GoGradLounge(Action):
    def __init__(self):
        Action.__init__(self, "Grad Lounge")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Go to the Grad Lounge"
    
    # if treasure is unlocked we go into that room
    # otherwise stay in the basement
    def get_destination(self):
        game = get_game()
        game.get_room('councilroom', CouncilRoom).locked = True
        game.get_room('councilroom', CouncilRoom).inventory.clear()
        #while (len(game.get_room('councilroom', CouncilRoom).inventory) > 0):
            #game.get_room('councilroom', CouncilRoom).inventory.pop()
        return 'gradlounge'
    
    #def is_enabled(self):
       # game = get_game()
       # if game.history[-1].solving:
       #     return False
       # else:
        #    return True
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
    
class AnswerTwo(Action):
    def __init__(self):
        Action.__init__(self, "AnswerTwo")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Answer: 2"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'councilroom'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"    
    
    def do_action(self,game,room,request):
        set_cutscene("You can't do simple math??!? Try again...")
        return
        
    def is_enabled(self):
        game = get_game()
        if (not game.history[-1].locked) & game.history[-1].solving:
                return True
        else:
            return False
        
class AnswerSix(Action):
    def __init__(self):
        Action.__init__(self, "AnswerSix")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Answer: 6"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'councilroom'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"    
    
    def do_action(self,game,room,request):
        set_cutscene("You can't do simple math??!? Try again...")
        return
        
    def is_enabled(self):
        game = get_game()
        if (not game.history[-1].locked) & game.history[-1].solving:
                return True
        else:
            return False

class AnswerFive(Action):
    def __init__(self):
        Action.__init__(self, "AnswerFive")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Answer: 5"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'councilroom'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get" 
    
    def do_action(self,game,room,request):
        set_cutscene("Great! Your classmate reminds you that there's a networking event where TechConnect was held. Maybe Dean Freeman is there.")
        room.solving = False
        return
    
    def is_enabled(self):
        game = get_game()
        if (not game.history[-1].locked) & game.history[-1].solving:
                return True
        else:
            return False
        
class goStupid(Action):
    def __init__(self):
        Action.__init__(self, "goStupid")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Go to 5th Floor Bathroom"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'stupid'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
    #def is_enabled(self):
        #game = get_game()
       # if game.history[-1].solving:
       #     return False
       # else:
       #     return True
        
class goLocked(Action):
    def __init__(self):
        Action.__init__(self, "goLocked")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Go to RM 326"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'stupid'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
    #def is_enabled(self):
    #    game = get_game()
     #   if game.history[-1].solving:
     #       return False
      #  else:
      #      return True